package com.keyue.controller;


import com.keyue.common.annotation.AnonymousAccess;
import com.keyue.common.constant.ServerResult;
import com.keyue.config.DataScope;
import com.keyue.domain.vo.admin.*;
import com.keyue.log.Log;
import com.keyue.service.admin.AdminUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @date 2018-11-23
 */
@Api(tags = "系统：用户管理")
@RestController
@RequestMapping("/keyue/admin/users")
public class UserController {

    @Value("${rsa.private_key}")
    private String privateKey;

    @Resource
    private AdminUserService userService;

    @Resource
    private DataScope dataScope;

    @Log("查询用户")
    @ApiOperation("查询用户")
    @PostMapping(value = "list_by_page")
    @AnonymousAccess
    public ServerResult listByPage(@RequestBody @Validated AdminUserQueryVO queryVO) {
        return userService.list(queryVO);
    }

    @Log("授权角色")
    @ApiOperation("授权角色")
    @PostMapping(value = "/auth_role")
    @AnonymousAccess
    public ServerResult authRole(@RequestBody @Validated AdminAuthUserVO userVO) {
        return userService.authRole(userVO);
    }

    @Log("新增用户")
    @ApiOperation("新增用户")
    @PostMapping(value = "/add")
    @AnonymousAccess
    public ServerResult add(@RequestBody @Validated AdminUserVO userVO) {
        return userService.add(userVO);
    }

    @Log("修改用户")
    @ApiOperation("修改用户")
    @PostMapping(value = "/edit")
    @AnonymousAccess
    public ServerResult edit(@RequestBody @Validated AdminUserVO userVO) {
        return userService.edit(userVO);
    }

    @Log("修改用户：个人中心")
    @ApiOperation("修改用户：个人中心")
    @AnonymousAccess
    public ServerResult center(@RequestBody @Validated AdminUserVO userVO) {
        return ServerResult.success();
    }

    @Log("删除用户")
    @ApiOperation("删除用户")
    @PostMapping(value = "/delete")
    @AnonymousAccess
    public ServerResult delete(@RequestBody @Validated AdminUserQueryVO queryVO) {
        return userService.deleteById(queryVO);
    }

    @Log("禁用用户")
    @ApiOperation("禁用用户")
    @PostMapping(value = "/opt")
    @AnonymousAccess
    public ServerResult opt(@RequestBody @Validated AdminUserQueryVO queryVO) {
        return userService.opt(queryVO);
    }

    @Log("修改密码")
    @ApiOperation("修改密码")
    @PostMapping(value = "/update_pass")
    @AnonymousAccess
    public ServerResult updatePass(@RequestBody @Validated UpdatePwdVO pwdVO) {
        return userService.updatePass(pwdVO);
    }

    @Log("重置密码")
    @ApiOperation("重置密码")
    @PostMapping(value = "/reset")
    @AnonymousAccess
    public ServerResult reset(@RequestBody @Validated ResetPwdVO resetPwdVO) {
        return userService.resetPwdVO(resetPwdVO);
    }

    @ApiOperation("修改头像")
    @AnonymousAccess
    public ServerResult updateAvatar(@RequestParam MultipartFile file) {
        return ServerResult.success();
    }

    @Log("修改邮箱")
    @ApiOperation("修改邮箱")
    @AnonymousAccess
    public ServerResult updateEmail(@RequestBody @Validated AdminUserQueryVO queryVO) {
        return ServerResult.success();
    }
}
